package face.yuque;

import java.util.Arrays;

/**
 * @author spf
 * @date 2024/12/12
 * @time 16:08
 */
// 数组中三个数的乘积最大
// 方法一：排序
public class MaxMutiple {

    public static void main(String[] args) {
        int[] nums = {1, 2, 3, 4, 5, 6};
        System.out.println(maxMutiple(nums));
    }

    private static int maxMutiple(int[] nums) {
        if (nums == null || nums.length < 3) {
            return 0;
        }

        Arrays.sort(nums);
        return Math.max(nums[0] * nums[1] * nums[nums.length - 1], nums[nums.length - 3] * nums[nums.length - 2] * nums[nums.length - 1]);
    }

}
